ISO/IEC 14882:2003 [1] requires initializer lists for arrays, structures and union types to be enclosed in a single pair of braces (though the
behaviour if this is not done is undefined). The rule given here goes further in requiring the use of additional braces to indicate nested
structures.
This forces the developer to explicitly consider and demonstrate the order in which elements of complex data types are initialized (e.g.
multi-dimensional arrays).
A similar principle applies to structures, and nested combinations of structures, arrays and other types.
Noncompliant code example
struct Pod {
int x;
int y;
};
struct PodPair {
Pod first;
Pod second;
};
int a1[3][2] = { 1, 2, 3, 4, 5, 6 }; // Noncompliant
Pod a2[2] = { 1, 2, 3, 4 }; // Noncompliant
PodPair a3 = { 1, 2 }; // Noncompliant, also missing initializers for `a3.second`
Compliant solution
int a1[3][2] = { {1, 2}, {3, 4}, {5, 6} }; // Compliant
Pod a2[2] = { {1, 2}, {3, 4} }; // Compliant
PodPair a3 = { {1, 2}, {} }; // Compliant